﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace WellDone
{
    public sealed partial class DiscountDialog : Page
    {
        public event EventHandler CloseRequested;
        public bool bCanceled = false;
        public bool bEntireOrder = false;
        public bool bDollarAmount = false;
        public decimal dAmount = 0;
        public DiscountDialog()
        {
            this.InitializeComponent();
            // Set the default selections
            rbPercent.IsChecked = true;
            rbEntireOrder.IsChecked = true;
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            // Determine selected values
            bEntireOrder = rbEntireOrder.IsChecked == true;
            bDollarAmount = rbDollarAmt.IsChecked == true;
            try
            {
                dAmount = Convert.ToDecimal(tbAmount.Text);
            }
            catch(FormatException)
            {
                dAmount = 0;
            }
            // Close the dialog
            if (this.CloseRequested != null)
            {
                this.CloseRequested(this, EventArgs.Empty);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            // Set "Canceled" 
            bCanceled = true;
            if (this.CloseRequested != null)
            {
                this.CloseRequested(this, EventArgs.Empty);
            }
        }
    }
}
